var userName;
var user_id;
var model_id;

//setCookie("recentlyViews",10002);


function startUserTabs(online){
	if(online==false){
		$("#userTabs_title").tabs();
		$("#userTabs_title").tabs({
							collapsible: true
							});
		$("#userTabs_title").tabs( "option", "selected", -1 );
		$("#userTabs_title").tabs({
				select:function(event,ui){
					var selected = $(this).tabs("option","selected");
					var touch = ui.index;
					if( selected<0){
						$("#welcomeInfo").toggle("blind",{},150);
						$(ui.panel).toggle("blind",{},150);
						}
					else if(selected==touch){
						$("#welcomeInfo").toggle("blind",{},150);
						$(ui.panel).toggle("blind",{},150);
						}
					else if(selected!=touch){
						$("div#userTabs_title div:nth-child("+(selected+2)+")").hide();
						$("div#userTabs_title div:nth-child("+(touch+2)+")").show();
						}
					}
			});
		$("div#userTabs_title div:nth-child(3)").hide();
		$("div#userTabs_title div:nth-child(2)").hide();
		$("#userTips").hide();
		}
	else{
		$("#userTabs_title").tabs();
		$("#userTabs_title").tabs({
							collapsible: true
							});
		$("#userTabs_title").tabs( "option", "selected", -1 );
		$("#userTabs_title").tabs({
				select:function(event,ui){
					var selected = $(this).tabs("option","selected");
					var touch = ui.index;
					if( selected<0){
						$("#welcomeInfo").toggle("blind",{},150);
						$(ui.panel).toggle("blind",{},150);
						}
					else if(selected==touch){
						$("#welcomeInfo").toggle("blind",{},150);
						$(ui.panel).toggle("blind",{},150);
						}
					else if(selected!=touch){
						$("div#userTabs_title div:nth-child("+(selected+2)+")").hide();
						$("div#userTabs_title div:nth-child("+(touch+2)+")").show();
						}
					}
			});
		$("div#userTabs_title div:nth-child(3)").hide();
		$("div#userTabs_title div:nth-child(2)").hide();
		$("#userTips").show();
		$("#userTabs_title").hide();
		$("#welcomeInfo").hide();
		}
	}

/*thanks “夏天以南”
0. 密码为空
1. 密码长度小于六位.或者密码只有一种组合
2. 密码长度大于五位, 且有两种组合.
3. 密码长度大于五位, 且有三种组合.
4. 密码长度大于五位, 且有四种组合.
*/
function checkPassword(password){
    if (password == ""){
		document.getElementById('checkPasswordInfo').innerHTML = "别忘了填写密码";
		}
    else if (password.length < 6){
		document.getElementById('checkPasswordInfo').innerHTML = "长度不能小于6位";
		document.getElementById('passwordCheckImg').src = "http://www.eizia.com/webpic/warning.png";
    	}
    else{
        var strong =  password.match(/[a-z](?![^a-z]*[a-z])|[A-Z](?![^A-Z]*[A-Z])|\d(?![^\d]*\d)|[^a-zA-Z\d](?![a-zA-Z\d]*[^a-zA-Z\d])/g).length;
		if(strong>1){
			
			document.getElementById('checkPasswordInfo').innerHTML = "符合要求";
			document.getElementById('passwordCheckImg').src = "http://www.eizia.com/webpic/correct.png";
			}
		/*else{
			document.getElementById('checkPasswordInfo').innerHTML = "请使用字母和数字的组合";
			document.getElementById('passwordCheckImg').src = "http://www.eizia.com/webpic/warning.png";
			}*/
		}	
	}
function checkRepassword(password,repassword){
	if(password && repassword){
		if(password == repassword){
			document.getElementById("repasswordCheckImg").src = "http://www.eizia.com/webpic/correct.png";
			document.getElementById("checkRepasswordInfo").innerHTML = "密码一致,不要忘记了";
			}else{
			document.getElementById("repasswordCheckImg").src = "http://www.eizia.com/webpic/warning.png";
			document.getElementById("checkRepasswordInfo").innerHTML = "两次输入的密码不一致";
				}
		}
	}
function checkEmail(email){
	if(!email){return;}
	var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
	if(reg.test(email)){
		document.getElementById("checkEmail").innerHTML = "邮箱填写正确";
		document.getElementById("mailAds").src = "http://www.eizia.com/webpic/correct.png";
		}
		else{
			document.getElementById("checkEmail").innerHTML = "邮箱填写不正确";
			document.getElementById("mailAds").src = "http://www.eizia.com/webpic/warning.png";
			}
	}
function clearCheckNameInfo(){
	document.getElementById("checkNameing").src = "http://www.eizia.com/webpic/blank.png";
	document.getElementById("checkNameInfo").innerHTML = "";
	}	
function clearCheckPasswordInfo(){
	document.getElementById("passwordCheckImg").src = "http://www.eizia.com/webpic/blank.png";
	document.getElementById("checkPasswordInfo").innerHTML = "";
	}
function clearCheckRepasswordInfo(){
	document.getElementById("repasswordCheckImg").src = "http://www.eizia.com/webpic/blank.png";
	document.getElementById("checkRepasswordInfo").innerHTML = "";
	}
	
function setCookie(name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/";
	}

function getCookie(name){
	if (document.cookie.length>0){
	  var c_start=document.cookie.indexOf(name + "=");
	  if (c_start!=-1){ 
		c_start=c_start + name.length+1;
		var c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
	}

function delCookie(name){
	var exdate = new Date();
	exdate.setTime(exdate.getTime()-1);
	var thatCookie = getCookie(name);
	if(thatCookie!=null){document.cookie = name+"="+thatCookie+";expires="+exdate.toGMTString();}
	}


function recordViewed(){
	var enjoyingNow = 	document.getElementById("showingModel") ?
						document.getElementById("showingModel").innerHTML : null;
	if(enjoyingNow){
		var already;
		var record = getCookie("recentlyViews");
		if(record){
			var recordModels = record.match(/\d+/g);
				for(var n=0;n<recordModels.length;n++){
					if(recordModels[n]==enjoyingNow){
						already = true;
						recordModels.splice(n,1);
						break;
						}
					}
			recordModels[recordModels.length] = enjoyingNow;
			if(recordModels.length>4){recordModels.shift();};
			var newRecord = recordModels.join("_");
			}
		else{
			var newRecord = enjoyingNow;
			}
		setCookie("recentlyViews",newRecord,100);
		}
	}
	
function displayRecentlyViews(pageState){
	if(pageState=="modelPage"){
		var loadUrl = "http://www.eizia.com/modelList.php";
		var elem = document.getElementById("recentlyList");
		var postValue = "state=userList&model_id="+document.getElementById("showingModel").innerHTML;
		loadPhpTo(loadUrl,postValue,elem,function(){
									var postValue = "state=relatedModels&model_id="+
													document.getElementById("showingModel").innerHTML;
									loadPhpTo(loadUrl,postValue,elem);
												  });
		}
	else if(pageState=="homePage"){
		var loadUrl = "http://www.eizia.com/modelList.php";
		var elem = document.getElementById("content");
		var postValue = "state=latestModels";
		loadPhpTo(loadUrl,postValue,elem,function(){
									var postValue = "state=normal&modelList="+getCookie("recentlyViews");
									loadPhpTo(loadUrl,postValue,elem);
												  });
		}
	
	}